//
//  PrivateChatMsg.m
//  SportSocial
//
//  Created by yull on 15/1/3.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "PrivateChatMsg.h"

@implementation PrivateChatMsg

+ (instancetype)privateChatMsgWithMsg:(ChatMsgBody *)msgBody
{
    PrivateChatMsg *privateChatMsg = [[PrivateChatMsg alloc] init];
    privateChatMsg.msgNum = msgBody.msgNum;
    privateChatMsg.sendId = msgBody.sendId;
    privateChatMsg.senderName = msgBody.senderName;
    privateChatMsg.receiveId = [CurrentUser shareInstance].userId;
    privateChatMsg.content = msgBody.msg;
    privateChatMsg.decodeContent = msgBody.msg;
    privateChatMsg.createTime = msgBody.createTime;
    privateChatMsg.msgType = msgBody.msgType;
    privateChatMsg.msgSubType = msgBody.msgType;
    privateChatMsg.url = msgBody.url;
    privateChatMsg.bigImageUrl = msgBody.bigImageUrl;
    privateChatMsg.isAck = NO;
    privateChatMsg.isRead = privateChatMsg.msgType != ChatMsgTypeAudio;
    privateChatMsg.msgLength = 0;
    privateChatMsg.picUploadPercent = 0;
    privateChatMsg.retainField = @"";
    privateChatMsg.roleType = ChatMsgRoleTypeReceive;
    privateChatMsg.sendStatus = ChatMsgSendStatusSuccess;
    privateChatMsg.icon = msgBody.icon;
    privateChatMsg.sex = msgBody.sex;
    
    privateChatMsg.audioRestTime = privateChatMsg.msgLength;
    privateChatMsg.audioStatus = ChatMsgAudioStatusNone;
    
    return privateChatMsg;
}

+ (instancetype)privateChatMsgWithResutlSet:(FMResultSet *)resultSet
{
    PrivateChatMsg *privateChatMsg = [[PrivateChatMsg alloc] init];
    privateChatMsg.dbId = [resultSet longLongIntForColumn:@"id"];
    privateChatMsg.msgNum = [resultSet longLongIntForColumn:@"msgNum"];
    privateChatMsg.sendId = [resultSet longLongIntForColumn:@"sendId"];
    privateChatMsg.senderName = [resultSet stringForColumn:@"senderName"];
    privateChatMsg.receiveId = [resultSet longLongIntForColumn:@"receiveId"];
    privateChatMsg.content = [resultSet stringForColumn:@"content"];
    privateChatMsg.decodeContent = [resultSet stringForColumn:@"decodeContent"];
    privateChatMsg.createTime = [resultSet longLongIntForColumn:@"createTime"];
    privateChatMsg.msgType = [resultSet intForColumn:@"msgType"];
    privateChatMsg.msgSubType = [resultSet intForColumn:@"msgSubType"];
    privateChatMsg.url = [resultSet stringForColumn:@"url"];
    privateChatMsg.bigImageUrl = [resultSet stringForColumn:@"bigImageUrl"];
    privateChatMsg.isAck = [resultSet boolForColumn:@"isAck"];
    privateChatMsg.isRead = [resultSet boolForColumn:@"isRead"];
    privateChatMsg.msgLength = [resultSet intForColumn:@"msgLength"];
    privateChatMsg.picUploadPercent = [resultSet doubleForColumn:@"picUploadPercent"];
    privateChatMsg.localPath = [resultSet stringForColumn:@"localPath"];
    privateChatMsg.retainField = [resultSet stringForColumn:@"retainField"];
    privateChatMsg.roleType = [resultSet intForColumn:@"roleType"];
    privateChatMsg.sendStatus = [resultSet intForColumn:@"sendStatus"];
    privateChatMsg.icon = [resultSet stringForColumn:@"icon"];
    
    privateChatMsg.audioRestTime = privateChatMsg.msgLength;
    privateChatMsg.audioStatus = ChatMsgAudioStatusNone;
    return privateChatMsg;
}
@end
